<?php
/*
 * 手机客户端 有奖问答 提交问题答案
 * 2013-12-05
 */
 
include "inc/public_header.php";

include "func/user.php";			//用户信息处理函数

$code = $_REQUEST["code"];			//活动代码
$answers = $_REQUEST["answers"];	//答案
$imsi = $_REQUEST["imsi"];			//手机识别码

//获取用户信息
$uInfoArr = user_getInfoFromUUID();
if(!$uInfoArr){
	echo json_encode(array("success"=>"0","errCode"=>"0","msg"=>"没有获取到用户信息"));
	die;
}
$uid = $uInfoArr["uid"];

if(!$code){
	echo json_encode(array("success"=>"0","errCode"=>"-1","msg"=>"没有获取到活动代码"));
	die;
}

if(!$answers){
	echo json_encode(array("success"=>"0","errCode"=>"-1","msg"=>"没有获取到答案"));
	die;
}

//判断用户是否参与过答题
$sql = "select id from ac_question_user where acode='".$code."' and uid='".$uid."' and aresult=0";
$db->query($sql);
if(!$db->next_record()){
	echo json_encode(array("success"=>"0","errCode"=>"-1","msg"=>"没找到获取题目时插入的记录"));
	die;
}

//更新用户答题信息
$sql = "update ac_question_user set aresult=1,answer='".$answers."',imsi='".$imsi."' where acode='".$code."' and uid='".$uid."'";
$db->query($sql);
echo json_encode(array("success"=>"1"));
die;
?>